package com.feifan.monthhelper.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.feifan.monthhelper.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 爱爱保护适配器
 */
public class LoveProtectAdapter extends RecyclerView.Adapter<LoveProtectAdapter.ProtectHolder> {
    private List<String> protects = new ArrayList<>();

    @NonNull
    @Override
    public ProtectHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ProtectHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_love_protect, null));
    }

    @Override
    public void onBindViewHolder(@NonNull ProtectHolder protectHolder, int i) {
        protectHolder.tvProtect.setText(protects.get(i));
    }

    public List<String> getProtects() {
        return protects;
    }

    @Override
    public int getItemCount() {
        return protects == null ? 0 : protects.size();
    }

    public void clear() {
        protects.clear();
        notifyDataSetChanged();
    }

    public void replace(List<String> data) {
        protects.clear();
        protects.addAll(data);
        notifyDataSetChanged();
    }

    class ProtectHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_protect)
        TextView tvProtect;
        @BindView(R.id.iv_delete_protect)
        ImageView ivDeleteProtect;

        public ProtectHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
